home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
common
/
AsyncSocket.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
7KB
|
215 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import socket
from socket import _socket as socket
import threading
import AsyncoreThread
import util
import traceback
import sys
import logging
log = logging.getLogger('AsyncSocket')
from asynchat import async_chat as _async_chat
from asyncore import compact_traceback
import asyncore
_ok_errors = set((asyncore.EINPROGRESS, asyncore.EALREADY, asyncore.EWOULDBLOCK))
class async_chat(_async_chat):
def connect(self, address):
self.connected = False
err = self.socket.connect_ex(address)
if err in _ok_errors:
return None
if err in (0, asyncore.EISCONN):
self.addr = address
self.connected = True
self.handle_connect()
else:
raise socket.error, (err, asyncore.errorcode.get(err, 'unknown'))
class AsyncSocket(object, async_chat):
def __init__(self, conn = None):
object.__init__(self)
self._lock = threading.RLock()
self._AsyncSocket__refcount = 0
self._proxy_setup = False
self._AsyncSocket__proxysocket = None
self._handlers = []
self.data = ''
if conn is False:
async_chat.__init__(self)
self._AsyncSocket__refcount += 1
AsyncoreThread.start()
elif conn is None:
async_chat.__init__(self)
self.make_socket()
else:
async_chat.__init__(self, conn)
self._AsyncSocket__refcount += 1
AsyncoreThread.start()
def make_socket(self, proxy = True):
if getattr(self, '_fileno', None) is not None:
self.del_channel()
if proxy:
proxy = util.GetProxyInfo()
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self._AsyncSocket__refcount += 1
AsyncoreThread.start()
make_socket = util.lock(make_socket)
def bind(self, addr):
retval = self.socket.bind(addr)
self.addr = self.socket.getsockname()
return retval
def log_info(self, message, type = 'info'):
if __debug__ or type != 'info':
etype = sys.exc_info()[0]
if etype is not None:
traceback.print_exc()
def connect(self, address, use_proxy = True, callback = None):
if use_proxy:
proxyinfo = self.GetProxyInfo()
else:
proxyinfo = { }
log.info('asyncsocket.connect%r', address)
if isinstance(self, ProxySocket):
log.info('\t\twas already a proxy socket')
old_error = (None, callback.error)
callback.error = lambda : (self.handle_close(), old_error())
async_chat.connect(self, address)
elif not (self._proxy_setup) and proxyinfo:
log.info('\t\tneed to setup proxies')
sck = self.socket
self.del_channel()
psck = ProxySocket(proxyinfo, sck, self.set_socket, callback)
self._AsyncSocket__proxysocket = psck
psck.connect(address)
elif self._proxy_setup:
log.info('\t\tproxy was already setup, calling handle_connect')
self.connected = True
self.handle_connect()
elif not proxyinfo:
log.info('\t\tno proxy neecessary')
self._proxy_setup = True
(None, AsyncoreThread.call_later)((lambda : async_chat.connect(self, address)), callback = callback)
else:
log.info('\t\terrr you didnt finish')
connect = util.callsback(connect)
def set_socket(self, sock, map = None):
async_chat.set_socket(self, sock, map)
return self
def GetProxyInfo(self):
return util.GetProxyInfo()
def close(self):
def _doit():
log.info('closing socket %r', self)
psck = self._AsyncSocket__proxysocket
if psck is not None:
log.info('Closing proxy socket: %r', psck)
psck.close()
self._AsyncSocket__proxysocket = None
async_chat.close(self)
AsyncoreThread.call_later(_doit)
def close_when_done(self):
(AsyncoreThread.call_later,)((lambda : async_chat.close_when_done(self)))
def collect_incoming_data(self, data):
self.data += data
def push_handler(self, h):
self._handlers.append(h)
def pop_handler(self):
self._handlers.pop()
def found_terminator(self):
data = self.data
self.data = ''
return self.handle_data(data)
def handle_data(self, data):
if self._handlers:
return self._handlers[-1](data)
else:
return data
def handle_close(self):
while self._handlers:
self.pop_handler()
def handle_error(self, e = None):
if getattr(e, 'verbose', True):
import traceback
traceback.print_exc()
log.error('Exception for %r: %r', self, e)
if e is None:
self.close()
return None
try:
raise e
except socket.error:
log.critical('Closing socket %r due to socket error', self)
self.close()
except Exception:
log.error('Unexpected exception in AsyncSocket.handle_error: %r', e)
def handle_expt(self):
log.critical('%r: handle_expt (OOB data)...closing', self)
self.close()
def handle_error(self, e = None):
(nil, t, v, tbinfo) = compact_traceback()
try:
self_repr = repr(self)
except:
self_repr = '<__repr__(self) failed for object at %0x>' % id(self)
self.log_info('uncaptured python exception, closing channel %s (%s:%s %s)' % (self_repr, t, v, tbinfo), 'error')
self.close()
from proxysockets import ProxySocket